package com.ourcraft.informationcollectionsystem.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.Getter;
import org.apache.ibatis.type.JdbcType;

import java.sql.Date;

import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@TableName("InvestigationPeriodPattern")
public class InvestigationPeriodPattern {
    @TableId(type = IdType.AUTO)
    private Integer patternId;
    private String patternName;
    @TableField(value = "pattern_valid_start_date", jdbcType = JdbcType.TIMESTAMP)
    private Date patternValidStartDate;
    @TableField(value = "pattern_valid_end_date", jdbcType = JdbcType.TIMESTAMP)
    private Date patternValidEndDate;
    private Integer patternInvLength;
    private Integer patternInterval;
    private String patternDescription;
    private Boolean patternStatus;

    public InvestigationPeriodPattern(Integer patternId, String patternName, Date patternValidStartDate, Date patternValidEndDate, Integer patternInvLength, Integer patternInterval, String patternDescription) {
        this.patternId = patternId;
        this.patternName = patternName;
        this.patternValidStartDate = patternValidStartDate;
        this.patternValidEndDate = patternValidEndDate;
        this.patternInvLength = patternInvLength;
        this.patternInterval = patternInterval;
        this.patternDescription = patternDescription;
        this.patternStatus = true;
    }

    // 需要将前端的‘2023-11-4’的字符串日期转化为sql.Date
    public InvestigationPeriodPattern(JSONObject param) {
        this.patternId = param.getInteger("patternId");
        this.patternName = param.getString("patternName");
        this.patternDescription = param.getString("patternDescription");
        this.patternInvLength = param.getInteger("patternInvLength");
        this.patternInterval = param.getInteger("patternInterval");
        this.patternValidStartDate = Date.valueOf(param.getString("patternValidStartDate"));
        this.patternValidEndDate = Date.valueOf(param.getString("patternValidEndDate"));
        this.patternStatus = param.getBoolean("patternStatus") != null ? param.getBoolean("patternStatus") : true;
    }
}
